﻿using iMES.Core.BaseProvider;
using iMES.Core.Enums;
using iMES.Core.Extensions;
using iMES.Core.Extensions.AutofacManager;
using iMES.Core.Utilities;
using iMES.Entity.DomainModels;
using iMES.Mass.IRepositories;
using iMES.Mass.IServices;
using iMES.Mass.Repositories;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;

namespace iMES.Mass.Services
{
    public partial class Mass_DetectionTemplateService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IMass_DetectionTemplateRepository mass_DetectionTemplateRepository;//访问数据库
        private readonly IMass_DetectionTemplate_ProductRepository mass_DetectionTemplate_ProductRepository;//访问数据库
        private readonly IMass_DetectionTemplate_ItemRepository mass_DetectionTemplate_ItemRepository;//访问数据库

        [ActivatorUtilitiesConstructor]
        public Mass_DetectionTemplateService(
            IHttpContextAccessor httpContextAccessor,
            IMass_DetectionTemplateRepository mass_DetectionTemplateRepository,
            IMass_DetectionTemplate_ProductRepository mass_DetectionTemplate_ProductRepository,
            IMass_DetectionTemplate_ItemRepository mass_DetectionTemplate_ItemRepository
            ) : base(mass_DetectionTemplateRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            this.mass_DetectionTemplateRepository = mass_DetectionTemplateRepository;
            this.mass_DetectionTemplate_ProductRepository = mass_DetectionTemplate_ProductRepository;
            this.mass_DetectionTemplate_ItemRepository = mass_DetectionTemplate_ItemRepository;
        }

        /// <summary>
        /// 获取table1的数据 检测项的数据
        /// </summary>
        /// <param name="loadData"></param>
        /// <returns></returns>
        public async Task<object> GetTable1Data(PageDataOptions loadData)
        {
            List<where> list = loadData.Wheres.DeserializeObject<List<where>>();
            int total = await Mass_DetectionTemplate_ItemRepository.intance.FindAsIQueryable(x => x.Mass_DetectionTemplate_Item_TemplateId == list[0].value.GetInt()).CountAsync();

            var data = await Mass_DetectionTemplate_ItemRepository.intance.FindAsIQueryable(x => x.Mass_DetectionTemplate_Item_TemplateId == list[0].value.GetInt())
                .TakeOrderByPage(1, 10, x => new Dictionary<object, QueryOrderBy>() { { x.CreateDate, QueryOrderBy.Desc } })
                .Select(x => new
                {
                    x.Mass_DetectionTemplate_Item_ItemId,
                    x.Mass_DetectionTemplate_Item_TemplateId,
                    x.Mass_DetectionTemplate_Item_DetItemId,
                    x.Mass_DetectionTemplate_Item_DetItemType,
                    x.Mass_DetectionTemplate_Item_DetItemTool,
                    x.Mass_DetectionTemplate_Item_DetItemCode,
                    x.Mass_DetectionTemplate_Item_DetItemName,
                    x.Mass_DetectionTemplate_Item_TestingRequire,
                    x.Mass_DetectionTemplate_Item_StandardValue,
                    x.Mass_DetectionTemplate_Item_ErrorUp,
                    x.Mass_DetectionTemplate_Item_ErrorDown,
                    x.Mass_DetectionTemplate_Item_Remark,
                    x.CreateID,
                    x.Creator,
                    x.CreateDate,
                    x.ModifyID,
                    x.Modifier,
                    x.ModifyDate,
                })
                .ToListAsync();
            object gridData = new { rows = data, total };
            return gridData;
        }

        /// <summary>
        /// 获取table2的数据 产品表的数据
        /// </summary>
        /// <param name="loadData"></param>
        /// <returns></returns>
        public async Task<object> GetTable2Data(PageDataOptions loadData)
        {
            List<where> list = loadData.Wheres.DeserializeObject<List<where>>();
            int total = await Mass_DetectionTemplate_ProductRepository.Intance.FindAsIQueryable
                (x => x.Mass_DetectionTemplate_Product_Template_ID == list[0].value.GetInt()).CountAsync();

            var data = await Mass_DetectionTemplate_ProductRepository.Intance.FindAsIQueryable
                (x => x.Mass_DetectionTemplate_Product_Template_ID == list[0].value.GetInt())
                .TakeOrderByPage(1, 10, x => new Dictionary<object, QueryOrderBy>() { { x.CreateDate, QueryOrderBy.Desc } })
                .Select(x => new
                {
                    x.Mass_DetectionTemplate_Product_Id,
                    x.Mass_DetectionTemplate_Product_Template_ID,
                    x.Mass_DetectionTemplate_Product_Product_ID,
                    x.Mass_DetectionTemplate_Product_ProductName,
                    x.Mass_DetectionTemplate_Product_ProductCode,
                    x.Mass_DetectionTemplate_Product_ProductStandard,
                    x.Mass_DetectionTemplate_Product_DetectMinNum,
                    x.Mass_DetectionTemplate_Product_UnqualifiedMaxNum,
                    x.Mass_DetectionTemplate_Product_FatalDefectRate,
                    x.Mass_DetectionTemplate_Product_CriticalDefectRate,
                    x.Mass_DetectionTemplate_Product_MinorDefectRate,
                    x.Mass_DetectionTemplate_Product_Remark,
                    x.CreateID,
                    x.Creator,
                    x.CreateDate,
                    x.ModifyID,
                    x.Modifier,
                    x.ModifyDate,
                }).ToListAsync();
            object gridData = new { rows = data, total };
            return gridData;
        }


        WebResponseContent webResponse = new WebResponseContent();
        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="saveDataModel"></param>
        /// <returns></returns>
        public override WebResponseContent Add(SaveModel saveDataModel)
        {
            try
            {
                //此处saveModel是从前台提交的原生数据，可对数据进修改过滤
                AddOnExecuting = (Mass_DetectionTemplate model, object list) =>
                {
                    if (string.IsNullOrWhiteSpace(model.Mass_DetectionTemplate_Code))
                        model.Mass_DetectionTemplate_Code = GetMass_DetectionItemsCode(model);
                    //判断是否有重复的编码
                    if (repository.Exists(x => x.Mass_DetectionTemplate_Code == model.Mass_DetectionTemplate_Code))
                    {
                        return webResponse.Error("检测模版编码已存在！");
                    }
                    //判断是否存在同名
                    if (repository.Exists(x => x.Mass_DetectionTemplate_Name == model.Mass_DetectionTemplate_Name))
                    {
                        return webResponse.Error("检测模版名称已存在！");
                    }
                    return webResponse.OK();
                };

                TableExtra tableExtra = saveDataModel.Extra.ToString().DeserializeObject<TableExtra>();
                AddOnExecuted = (Mass_DetectionTemplate template, object obj) =>
                {
                    #region 添加检测模板中的检测项
                    List<Mass_DetectionTemplate_Item> itemlist = tableExtra.Table1List.Select(x => new Mass_DetectionTemplate_Item
                    {
                        Mass_DetectionTemplate_Item_ItemId = x.Mass_DetectionTemplate_Item_ItemId,
                        Mass_DetectionTemplate_Item_TemplateId = template.Mass_DetectionTemplate_ID,
                        Mass_DetectionTemplate_Item_DetItemId = x.Mass_DetectionTemplate_Item_DetItemId,
                        Mass_DetectionTemplate_Item_DetItemType = x.Mass_DetectionTemplate_Item_DetItemType,
                        Mass_DetectionTemplate_Item_DetItemTool = x.Mass_DetectionTemplate_Item_DetItemTool,
                        Mass_DetectionTemplate_Item_DetItemCode = x.Mass_DetectionTemplate_Item_DetItemCode,
                        Mass_DetectionTemplate_Item_DetItemName = x.Mass_DetectionTemplate_Item_DetItemName,
                        Mass_DetectionTemplate_Item_TestingRequire = x.Mass_DetectionTemplate_Item_TestingRequire,
                        Mass_DetectionTemplate_Item_StandardValue = x.Mass_DetectionTemplate_Item_StandardValue,
                        Mass_DetectionTemplate_Item_ErrorUp = x.Mass_DetectionTemplate_Item_ErrorUp,
                        Mass_DetectionTemplate_Item_ErrorDown = x.Mass_DetectionTemplate_Item_ErrorDown,
                        Mass_DetectionTemplate_Item_Remark = x.Mass_DetectionTemplate_Item_Remark,
                    }).ToList();
                    List<Mass_DetectionTemplate_Item> additemlist = itemlist.Where(x => x.Mass_DetectionTemplate_Item_ItemId == 0).ToList();
                    additemlist.ForEach(x =>
                    {
                        x.SetCreateDefaultVal();
                    });
                    repository.AddRange(additemlist);
                    #endregion


                    #region 添加检测模板中的产品信息
                    List<Mass_DetectionTemplate_Product> prolist = tableExtra.Table2List.Select(x => new Mass_DetectionTemplate_Product
                    {
                        Mass_DetectionTemplate_Product_Id = x.Mass_DetectionTemplate_Product_Id,
                        Mass_DetectionTemplate_Product_Template_ID = template.Mass_DetectionTemplate_ID,
                        Mass_DetectionTemplate_Product_Product_ID = x.Mass_DetectionTemplate_Product_Product_ID,
                        Mass_DetectionTemplate_Product_ProductName = x.Mass_DetectionTemplate_Product_ProductName,
                        Mass_DetectionTemplate_Product_ProductCode = x.Mass_DetectionTemplate_Product_ProductCode,
                        Mass_DetectionTemplate_Product_ProductStandard = x.Mass_DetectionTemplate_Product_ProductStandard,
                        Mass_DetectionTemplate_Product_DetectMinNum = x.Mass_DetectionTemplate_Product_DetectMinNum,
                        Mass_DetectionTemplate_Product_UnqualifiedMaxNum = x.Mass_DetectionTemplate_Product_UnqualifiedMaxNum,
                        Mass_DetectionTemplate_Product_FatalDefectRate = x.Mass_DetectionTemplate_Product_FatalDefectRate,
                        Mass_DetectionTemplate_Product_CriticalDefectRate = x.Mass_DetectionTemplate_Product_CriticalDefectRate,
                        Mass_DetectionTemplate_Product_MinorDefectRate = x.Mass_DetectionTemplate_Product_MinorDefectRate,
                        Mass_DetectionTemplate_Product_Remark = x.Mass_DetectionTemplate_Product_Remark,
                    }).ToList();
                    List<Mass_DetectionTemplate_Product> addprolist = prolist.Where(x => x.Mass_DetectionTemplate_Product_Id == 0).ToList();
                    additemlist.ForEach(x =>
                    {
                        x.SetCreateDefaultVal();
                    });
                    repository.AddRange(addprolist);
                    #endregion

                    repository.SaveChanges();
                    return WebResponseContent.Instance.OK();
                };
                return base.Add(saveDataModel);
            }
            catch (Exception ex)
            {
                webResponse.Status = false;
                webResponse.Message = "请检查数据格式是否正确！";
                Console.WriteLine(ex);
                throw;
            }
        }
        /// <summary>
        /// 编辑操作
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public override WebResponseContent Update(SaveModel saveModel)
        {
            try
            {
                //取出校验完成后的从表1.2的数据
                TableExtra tableExtra = saveModel.Extra.ToString().DeserializeObject<TableExtra>();

                //保存到数据库前
                UpdateOnExecuting = (Mass_DetectionTemplate template, object obj, object obj2, List<object> list) =>
                {
                    return WebResponseContent.Instance.OK();
                };

                //App_ReportPrice 此处已经提交了数据库，处于事务中
                UpdateOnExecuted = (Mass_DetectionTemplate template, object obj, object obj2, List<object> list) =>
                {
                    #region 检测模板-检测项
                    List<Mass_DetectionTemplate_Item> newsList = tableExtra.Table1List.Select(x => new Mass_DetectionTemplate_Item
                    {
                        Mass_DetectionTemplate_Item_ItemId = x.Mass_DetectionTemplate_Item_ItemId,
                        Mass_DetectionTemplate_Item_TemplateId = template.Mass_DetectionTemplate_ID,
                        Mass_DetectionTemplate_Item_DetItemId = x.Mass_DetectionTemplate_Item_DetItemId,
                        Mass_DetectionTemplate_Item_DetItemType = x.Mass_DetectionTemplate_Item_DetItemType,
                        Mass_DetectionTemplate_Item_DetItemTool = x.Mass_DetectionTemplate_Item_DetItemTool,
                        Mass_DetectionTemplate_Item_DetItemCode = x.Mass_DetectionTemplate_Item_DetItemCode,
                        Mass_DetectionTemplate_Item_DetItemName = x.Mass_DetectionTemplate_Item_DetItemName,
                        Mass_DetectionTemplate_Item_TestingRequire = x.Mass_DetectionTemplate_Item_TestingRequire,
                        Mass_DetectionTemplate_Item_StandardValue = x.Mass_DetectionTemplate_Item_StandardValue,
                        Mass_DetectionTemplate_Item_ErrorUp = x.Mass_DetectionTemplate_Item_ErrorUp,
                        Mass_DetectionTemplate_Item_ErrorDown = x.Mass_DetectionTemplate_Item_ErrorDown,
                        Mass_DetectionTemplate_Item_Remark = x.Mass_DetectionTemplate_Item_Remark,
                    }).ToList();

                    List<Mass_DetectionTemplate_Item> addList = newsList.Where(x => x.Mass_DetectionTemplate_Item_ItemId == 0).ToList();
                    addList.ForEach(x => { x.SetCreateDefaultVal(); });

                    List<int> editIds = newsList.Where(x => x.Mass_DetectionTemplate_Item_ItemId != 0).Select(y => y.Mass_DetectionTemplate_Item_ItemId).ToList();

                    addList.ForEach(x => { x.SetModifyDefaultVal(); });

                    List<int> existsIds = Mass_DetectionTemplate_ItemRepository.intance.FindAsIQueryable(x => editIds.Contains(x.Mass_DetectionTemplate_Item_ItemId)).Select(y => y.Mass_DetectionTemplate_Item_ItemId).ToList();

                    List<Mass_DetectionTemplate_Item> updateList = newsList.Where(x => existsIds.Contains(x.Mass_DetectionTemplate_Item_ItemId)).ToList();

                    updateList.ForEach(x => { x.SetModifyDefaultVal(); });

                    repository.AddRange(addList);

                    repository.UpdateRange(updateList, x => new
                    {
                        x.Mass_DetectionTemplate_Item_DetItemTool,
                        x.Mass_DetectionTemplate_Item_TestingRequire,
                        x.Mass_DetectionTemplate_Item_StandardValue,
                        x.Mass_DetectionTemplate_Item_ErrorUp,
                        x.Mass_DetectionTemplate_Item_ErrorDown,
                        x.Mass_DetectionTemplate_Item_Remark,
                        x.Modifier,
                        x.ModifyDate,
                        x.ModifyID
                    });
                    #endregion

                    #region 检测模板-产品信息
                    List<Mass_DetectionTemplate_Product> newsList2 = tableExtra.Table2List.Select(x => new Mass_DetectionTemplate_Product
                    {
                        Mass_DetectionTemplate_Product_Id = x.Mass_DetectionTemplate_Product_Id,
                        Mass_DetectionTemplate_Product_Template_ID = template.Mass_DetectionTemplate_ID,
                        Mass_DetectionTemplate_Product_Product_ID = x.Mass_DetectionTemplate_Product_Product_ID,
                        Mass_DetectionTemplate_Product_ProductName = x.Mass_DetectionTemplate_Product_ProductName,
                        Mass_DetectionTemplate_Product_ProductCode = x.Mass_DetectionTemplate_Product_ProductCode,
                        Mass_DetectionTemplate_Product_ProductStandard = x.Mass_DetectionTemplate_Product_ProductStandard,
                        Mass_DetectionTemplate_Product_DetectMinNum = x.Mass_DetectionTemplate_Product_DetectMinNum,
                        Mass_DetectionTemplate_Product_UnqualifiedMaxNum = x.Mass_DetectionTemplate_Product_UnqualifiedMaxNum,
                        Mass_DetectionTemplate_Product_FatalDefectRate = x.Mass_DetectionTemplate_Product_FatalDefectRate,
                        Mass_DetectionTemplate_Product_CriticalDefectRate = x.Mass_DetectionTemplate_Product_CriticalDefectRate,
                        Mass_DetectionTemplate_Product_MinorDefectRate = x.Mass_DetectionTemplate_Product_MinorDefectRate,
                        Mass_DetectionTemplate_Product_Remark = x.Mass_DetectionTemplate_Product_Remark,
                    }).ToList();

                    List<Mass_DetectionTemplate_Product> addList2 = newsList2.Where(x => x.Mass_DetectionTemplate_Product_Id == 0).ToList();

                    addList2.ForEach(x => { x.SetCreateDefaultVal(); });

                    List<int> editIds2 = newsList2.Where(x => x.Mass_DetectionTemplate_Product_Id != 0).Select(s => s.Mass_DetectionTemplate_Product_Id).ToList();
                    addList2.ForEach(x => { x.SetModifyDefaultVal(); });

                    List<int> existsIds2 = Mass_DetectionTemplate_ProductRepository.Intance.FindAsIQueryable(x => editIds.Contains(x.Mass_DetectionTemplate_Product_Id)).Select(s => s.Mass_DetectionTemplate_Product_Id).ToList();

                    List<Mass_DetectionTemplate_Product> updateList2 = newsList2.Where(x => existsIds2.Contains(x.Mass_DetectionTemplate_Product_Id)).ToList();

                    updateList2.ForEach(x => { x.SetModifyDefaultVal(); });

                    repository.AddRange(addList2);

                    repository.UpdateRange(updateList2, x => new
                    {
                        x.Mass_DetectionTemplate_Product_DetectMinNum,
                        x.Mass_DetectionTemplate_Product_UnqualifiedMaxNum,
                        x.Mass_DetectionTemplate_Product_FatalDefectRate,
                        x.Mass_DetectionTemplate_Product_CriticalDefectRate,
                        x.Mass_DetectionTemplate_Product_MinorDefectRate,
                        x.Mass_DetectionTemplate_Product_Remark,
                        x.Modifier,
                        x.ModifyDate,
                        x.ModifyID
                    });
                    #endregion
                    //最终保存
                    repository.SaveChanges();
                    return WebResponseContent.Instance.OK();
                };
                return base.Update(saveModel);
            }
            catch (Exception ex)
            {
                webResponse.Status = false;
                webResponse.Message = "请检查数据格式是否正确！";
                Console.WriteLine(ex);
                return webResponse;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="delList"></param>
        /// <returns></returns>
        public override WebResponseContent Del(object[] keys, bool delList = true)
        {
            for (int i = 0; i < keys.Length; i++)
            {
                List<object> idsProject = Mass_DetectionTemplateRepositroy.Intance.FindAsIQueryable
                    (x => x.Mass_DetectionTemplate_ID == keys[i].GetInt()).Select(s => (object)s.Mass_DetectionTemplate_ID).ToList();
                object[] arrayProject = idsProject.ToArray();
                mass_DetectionTemplateRepository.DeleteWithKeys(arrayProject, true);
            }
            //最终保存
            repository.SaveChanges();
            return base.Del(keys, true);
        }
        /// <summary>
        /// 自动生成编码
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public string GetMass_DetectionItemsCode(Mass_DetectionTemplate entity)
        {
            // 若有编码，则直接返回
            if (!string.IsNullOrEmpty(entity.Mass_DetectionTemplate_Code))
            {
                return entity.Mass_DetectionTemplate_Code;
            }
            else
            {
                // 自动生成编码
                var list = Mass_DetectionTemplateRepositroy.Intance.FindAsIQueryable
                    (x => x.Mass_DetectionTemplate_Code.StartsWith("JCBM")).OrderByDescending(x => x.Mass_DetectionTemplate_Code).ToList().FirstOrDefault();
                if (list == null)
                {
                    return "JCBM" + DateTime.Now.ToString("yyyyMMdd") + "00001";
                }
                else
                {
                    string code = list.Mass_DetectionTemplate_Code.Substring(12, 5);
                    int num = int.Parse(code) + 1;
                    return "JCBM" + DateTime.Now.ToString("yyyyMMdd") + num.ToString().PadLeft(5, '0');
                }
            }
        }
    }

    public class TableExtra
    {
        /// <summary>
        /// 从表1
        /// </summary>
        public List<Table1_Mass_DetectionTemplate_Item> Table1List { get; set; }

        /// <summary>
        /// 从表2
        /// </summary>
        public List<Table2_Mass_DetectionTemplate_Product> Table2List { get; set; }
    }

    public class Table1_Mass_DetectionTemplate_Item
    {
        /// <summary>
        /// 检测模版检测项主键
        /// </summary>
        [Key]
        [Display(Name = "检测模版检测项主键")]
        [Column(TypeName = "int")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public int Mass_DetectionTemplate_Item_ItemId { get; set; }

        /// <summary>
        /// 检测模版主键
        /// </summary>
        [Display(Name = "检测模版主键")]
        [Column(TypeName = "int")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public int Mass_DetectionTemplate_Item_TemplateId { get; set; }

        /// <summary>
        /// 检测项主键
        /// </summary>
        [Display(Name = "检测项主键")]
        [Column(TypeName = "int")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public int Mass_DetectionTemplate_Item_DetItemId { get; set; }

        /// <summary>
        /// 检测项类型
        /// </summary>
        [Display(Name = "检测项类型")]
        [MaxLength(200)]
        [Column(TypeName = "nvarchar(200)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Item_DetItemType { get; set; }

        /// <summary>
        /// 检测工具
        /// </summary>
        [Display(Name = "检测工具")]
        [MaxLength(200)]
        [Column(TypeName = "nvarchar(200)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Item_DetItemTool { get; set; }

        /// <summary>
        /// 检测项编码
        /// </summary>
        [Display(Name = "检测项编码")]
        [MaxLength(100)]
        [Column(TypeName = "varchar(100)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Item_DetItemCode { get; set; }

        /// <summary>
        /// 检测项名称
        /// </summary>
        [Display(Name = "检测项名称")]
        [MaxLength(100)]
        [Column(TypeName = "nvarchar(100)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Item_DetItemName { get; set; }

        /// <summary>
        /// 检测要求
        /// </summary>
        [Display(Name = "检测要求")]
        [MaxLength(200)]
        [Column(TypeName = "nvarchar(200)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Item_TestingRequire { get; set; }

        /// <summary>
        /// 标准值
        /// </summary>
        [Display(Name = "标准值")]
        [DisplayFormat(DataFormatString = "12,2")]
        [Column(TypeName = "decimal")]
        [Editable(true)]
        public decimal? Mass_DetectionTemplate_Item_StandardValue { get; set; }

        /// <summary>
        /// 误差上限
        /// </summary>
        [Display(Name = "误差上限")]
        [DisplayFormat(DataFormatString = "12,2")]
        [Column(TypeName = "decimal")]
        [Editable(true)]
        public decimal? Mass_DetectionTemplate_Item_ErrorUp { get; set; }

        /// <summary>
        /// 误差下限
        /// </summary>
        [Display(Name = "误差下限")]
        [DisplayFormat(DataFormatString = "12,2")]
        [Column(TypeName = "decimal")]
        [Editable(true)]
        public decimal? Mass_DetectionTemplate_Item_ErrorDown { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [Display(Name = "备注")]
        [MaxLength(1000)]
        [Column(TypeName = "nvarchar(1000)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Item_Remark { get; set; }

        /// <summary> 
        /// 创建人编号
        /// </summary>
        [Display(Name = "创建人编号")]
        [Column(TypeName = "int")]
        [Editable(true)]
        public int? CreateID { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [Display(Name = "创建人")]
        [MaxLength(30)]
        [Column(TypeName = "nvarchar(30)")]
        [Editable(true)]
        public string Creator { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        [Column(TypeName = "datetime")]
        [Editable(true)]
        public DateTime? CreateDate { get; set; }

        /// <summary>
        ///修改人编号
        /// </summary>
        [Display(Name = "修改人编号")]
        [Column(TypeName = "int")]
        [Editable(true)]
        public int? ModifyID { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        [Display(Name = "修改人")]
        [MaxLength(30)]
        [Column(TypeName = "nvarchar(30)")]
        [Editable(true)]
        public string Modifier { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        [Display(Name = "修改时间")]
        [Column(TypeName = "datetime")]
        [Editable(true)]
        public DateTime? ModifyDate { get; set; }
    }

    public class Table2_Mass_DetectionTemplate_Product
    {
        /// <summary>
        /// 检测模版产品主键
        /// </summary>
        [Key]
        [Display(Name = "检测模版产品主键")]
        [Column(TypeName = "int")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public int Mass_DetectionTemplate_Product_Id { get; set; }

        /// <summary>
        /// 模版主键
        /// </summary>
        [Display(Name = "模版主键")]
        [Column(TypeName = "int")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public int Mass_DetectionTemplate_Product_Template_ID { get; set; }

        /// <summary>
        /// 产品主键
        /// </summary>
        [Display(Name = "产品主键")]
        [Column(TypeName = "int")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public int Mass_DetectionTemplate_Product_Product_ID { get; set; }

        /// <summary>
        /// 产品名称
        /// </summary>
        [Display(Name = "产品名称")]
        [MaxLength(100)]
        [Column(TypeName = "nvarchar(100)")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public string Mass_DetectionTemplate_Product_ProductName { get; set; }

        /// <summary>
        /// 产品编码
        /// </summary>
        [Display(Name = "产品编码")]
        [MaxLength(100)]
        [Column(TypeName = "nvarchar(100)")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public string Mass_DetectionTemplate_Product_ProductCode { get; set; }

        /// <summary>
        /// 产品型号
        /// </summary>
        [Display(Name = "产品型号")]
        [MaxLength(200)]
        [Column(TypeName = "nvarchar(200)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Product_ProductStandard { get; set; }

        /// <summary>
        /// 最低检测数
        /// </summary>
        [Display(Name = "最低检测数")]
        [Column(TypeName = "int")]
        [Editable(true)]
        public int? Mass_DetectionTemplate_Product_DetectMinNum { get; set; }

        /// <summary>
        /// 最大不合格数
        /// </summary>
        [Display(Name = "最大不合格数")]
        [Column(TypeName = "int")]
        [Editable(true)]
        public int? Mass_DetectionTemplate_Product_UnqualifiedMaxNum { get; set; }

        /// <summary>
        /// 致命缺陷率
        /// </summary>
        [Display(Name = "致命缺陷率")]
        [DisplayFormat(DataFormatString = "12,2")]
        [Column(TypeName = "decimal")]
        [Editable(true)]
        public decimal? Mass_DetectionTemplate_Product_FatalDefectRate { get; set; }

        /// <summary>
        /// 严重缺陷率
        /// </summary>
        [Display(Name = "严重缺陷率")]
        [DisplayFormat(DataFormatString = "12,2")]
        [Column(TypeName = "decimal")]
        [Editable(true)]
        public decimal? Mass_DetectionTemplate_Product_CriticalDefectRate { get; set; }

        /// <summary>
        /// 轻微缺陷率
        /// </summary>
        [Display(Name = "轻微缺陷率")]
        [DisplayFormat(DataFormatString = "12,2")]
        [Column(TypeName = "decimal")]
        [Editable(true)]
        public decimal? Mass_DetectionTemplate_Product_MinorDefectRate { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [Display(Name = "备注")]
        [MaxLength(1000)]
        [Column(TypeName = "nvarchar(1000)")]
        [Editable(true)]
        public string Mass_DetectionTemplate_Product_Remark { get; set; }

        /// <summary>
        /// 创建人编号
        /// </summary>
        [Display(Name = "创建人编号")]
        [Column(TypeName = "int")]
        [Editable(true)]
        public int? CreateID { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [Display(Name = "创建人")]
        [MaxLength(30)]
        [Column(TypeName = "nvarchar(30)")]
        [Editable(true)]
        public string Creator { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Display(Name = "创建时间")]
        [Column(TypeName = "datetime")]
        [Editable(true)]
        public DateTime? CreateDate { get; set; }

        /// <summary>
        /// 修改人编号
        /// </summary>
        [Display(Name = "修改人编号")]
        [Column(TypeName = "int")]
        [Editable(true)]
        public int? ModifyID { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        [Display(Name = "修改人")]
        [MaxLength(30)]
        [Column(TypeName = "nvarchar(30)")]
        [Editable(true)]
        public string Modifier { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        [Display(Name = "修改时间")]
        [Column(TypeName = "datetime")]
        [Editable(true)]
        public DateTime? ModifyDate { get; set; }
    }

    public class where
    {
        public string name { get; set; }
        public string value { get; set; }
    }
}
